<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="css/eui.css">
</head>
<body>
<div id="app">
    <input type="text" v-model="name" placeholder="姓名">
    <input type="text" v-model="salary" placeholder="工资">
    <input type="text" v-model="job" placeholder="工作">
    <input type="button" value="添加" @click="f()">
    <h1>员工列表</h1>
    <template>
        <el-table
                :data="arr"
                style="width: 100%">
            <el-table-column type="index"
                    label="编号"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="name"
                    label="姓名"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="salary"
                    label="工资"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="job"
                    label="工作">
            </el-table-column>
            <el-table-column label="操作">
                <!--scope代表每行对象的数据,里面的index属性代表下标,里面的row代表每行触发器的数组中的对象-->
                <template slot-scope="scope">
                    <el-popconfirm
                            title="这是一段内容确定删除吗？"
                            @confirm="handleDelete(scope.$index, scope.row)"
                    >
                        <el-button slot="reference" size="mini"
                                   type="danger">删除</el-button>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>
    </template>
</div>
</body>
<!-- import Vue before Element -->
<script src="js/vue.js"></script>
<!-- import JavaScript -->
<script src="js/eui.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                name: "", salary: "", job: "",
                arr: []
            }
        },
        methods: {
            f() {
                if (v.name.trim() == "" || v.salary.trim() == "" || v.job == "") {
                    v.$message.error("输入错误!")
                }
                v.arr.push({name: v.name, salary: v.salary, job: v.job});
                v.name = "";
                v.salary = "";
                v.job = "";
            },
            handleDelete(index, row) {
                console.log(index, row);
                v.arr.splice(index,1);
            }
        }
    })
</script>
</html>